﻿/* 功能:  商户资金账号管理
 * 创建人：kencery  创建时间：2018-2-3
 */
var ml = window.ml || {};
ml.admin = ml.admin || {};

ml.admin.capitalaccount = (function () {
    var defaults = {
        listUrl: "/CapitalAccount/List",
        getReceivablesByMerchantIdUrl: "/Merchant/GetReceivablesByMerchantId",
    };
    var opt = {};

    var columns = [{
        field: 'state',
        radio: true
    }, {
        title: '行号',
        field: 'number',
        align: 'center',
        hide: true,
        formatter: plscommon.tableNumber
    }, {
        title: '资金账户ID',
        field: 'Id',
    }, {
        title: '商户名称',
        field: 'Name',
        align: 'center'
    }, {
        title: '总金额',
        field: 'Balance',
        align: 'center',
    }, {
        title: '已提现金额',
        field: 'Withdrawed',
        align: 'center',
    }, {
        title: '剩余金额',
        field: 'ResidueMoney',
        align: 'center',
    }, {
        title: '最后更新时间',
        field: 'UpdateTime',
    }, {
        title: '创建时间',
        field: 'CreateTime'
    }];

    var initTable = function () {
        plscommon.bootstraptable({
            id: "#capitalaccountinfo",
            url: defaults.listUrl,
            queryParams: queryParams,
            uniqueId: "Id",
            columns: columns
        });
    };

    var queryParams = function (params) {
        return {
            offset: params.offset,             //后台计算显示数据信息
            pagesize: params.limit,            //每页显示多少行
            name_search: $("#name_search").val(),
        };
    };

    var clickEvent = function () {
        $("#btnQueryList").on("click", function () { btnQueryList(); });                        //按条件查询结果
        $("#btnReset").on("click", function () { btnReset(); });                                //清空文本框信息
        $("#btnReceivables").on("click", function () { btnReceivables(); });                    //查看收款方式
    };

    var btnQueryList = function () {
        plscommon.refreshTable("capitalaccountinfo");
    };

    var btnReset = function () {
        plscommon.resetFrom("formSearch");
    };

    var btnReceivables = function () {
        var data = plscommon.dialogWaring('capitalaccountinfo', 'QueryReceivables', 'QueryReceivablesOperation');
        if (!data.Id) {
            return false;
        }
        $("#HeadTitle_Receivables").text("(" + data.Name + ")商户收款方式");

        //发送请求调用查询后台返回数据
        $("#btnReceivables").prop("disabled", true);
        plscommon.ajax({
            disableId: "btnReceivables",
            url: defaults.getReceivablesByMerchantIdUrl,
            type: "GET",
            data: { id: data.MerchantId },
            success: function () {
                var data = this.data;
                if (data.length > 0) {
                    $("#QueryReceivablesTable").show();
                    $("#QueryReceivablesTableNo").hide();

                    //不为空写入查询出来的内容
                    $("#QueryReceivablesTable table tbody").html("");
                    var tbody_tr = "";
                    $.each(data, function (i, item) {
                        var defaultmarktext = item.DefaultMark == 0 ? "未默认" : "默认";
                        tbody_tr += "<tr><td>" + item.Method + "</td><td>" + item.OpeningBank + "</td><td>" + item.OpeningName + "</td>"
                            + "<td>" + item.OpeningAccount + "</td><td>" + item.ThirdAccount + "</td>"
                            + "<td>" + defaultmarktext + "</td><td>" + item.CreateTime + "</td></tr>";
                    });
                    $("#QueryReceivablesTable table tbody").append(tbody_tr);
                } else {
                    $("#QueryReceivablesTable").hide();
                    $("#QueryReceivablesTableNo").show();
                }
            }
        });
    }

    return {
        init: function (options) {
            $.extend(defaults, options || {});
            initTable();            //初始化Table表格
            clickEvent();           //触发事件
        }
    };
}());